<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Young
 */
interface Group {
    //put your code here
    public function addUser($_user);
    public function delUser($_user);
    public function getUser();
    public function releaseGroup();
}

class NormalGroup implements Group{
    private $groupName = "";
    protected $groupMember = array();
    public function addUser($_user) {
        array_push($this->groupMember, $_user);
    }
    public function delUser($_user) {
        for($i = 0; $i < sizeof($groupMember); $i++){
            if($groupMember[$i] == $_user){
                array_splice($groupMember, $i, 1);
                return;
            }
        }
    }
    public function getUser() {
        return $this->groupMember;
    }
    public function releaseGroup() {
        while(sizeof($groupMember) > 0){
            array_pop($groupMember);
        }
    }
    public static function createGroup($groupname,$administrator){
        echo $administrator;
        echo $groupname;
        $query = "INSERT INTO groups value('".$administrator."','".$groupname."','".$administrator."')";
        mysql_query($query);
    }
	public static function getAllGroup()
	{
		$DB = mysql_connect("localhost","root","12345");
		mysql_query("set names utf8");
		mysql_select_db("mynotes",$DB);
		$DBT = mysql_query("SELECT DISTINCT group_name FROM groups");
		$results = array();
		for ($i=0; $i< mysql_num_rows($DBT); $i++)
		{			
		  $row = mysql_fetch_array($DBT);
		  $gr = $row['group_name'];
		  $results[] = $gr;
		}  	
		return $results;
	}
	public static function deleteGroup($gname)
	{
		$DB = mysql_connect("localhost","root","12345");
		mysql_query("set names utf8");
		mysql_select_db("mynotes",$DB);
		mysql_query("delete from groups where group_name = '$gname'");
	}
}
?>
